package com.beilang.hotline.sys.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.beilang.base.core.dao.PaginationBaseDAO;
import com.beilang.base.pagination.PaginationHelper;
import com.beilang.base.util.StringUtil;
import com.beilang.hotline.sys.model.SysModel;
import com.beilang.hotline.sys.to.SearchTO;


public class SysDAO  extends PaginationBaseDAO {
	public SysModel createSys(SysModel sysModel) {
        sysModel.setDeleteInd("N");
        return (SysModel)this.save(sysModel);
	}
	
	public SysModel saveSys(SysModel sysModel) {
		return (SysModel)this.save(sysModel);
	}
	
	public void deleteSys(Long sysId){
        SysModel sys= this.getSys(sysId);
        sys.setDeleteInd("Y");
        this.save(sys);
	}
	
	public SysModel getSys(Long sysId){
		return (SysModel)this.get(SysModel.class, sysId);
	}
	
	public Integer searchCount(SearchTO searchTO) {
        Map map = new HashMap();       
        String sysName=StringUtil.convertEmpty2Null(searchTO.getSysName());
        if(sysName!=null)sysName="%"+sysName+"%";
        map.put("sysName", sysName);
        return (Integer) getSqlMapClientTemplate().queryForObject("searchSysCount", map);
    }

    public List searchList(PaginationHelper helper, SearchTO searchTO) {
        Map map = new HashMap();
        String sysName=StringUtil.convertEmpty2Null(searchTO.getSysName());
        if(sysName!=null)sysName="%"+sysName+"%";      
        map.put("sysName", sysName);
        map = constructPaginationMap(helper, map);
        return getSqlMapClientTemplate().queryForList("searchSysList", map);
    }
    
    protected String mapSortField(String dataField){
        //return "record_id";
        if(StringUtil.isNullOrBlank(dataField))return dataField;
    	if(dataField.equalsIgnoreCase("sysName")) return "system_name";
        if(dataField.equalsIgnoreCase("customerViewIndDesc")) return "customerViewInd";
        return dataField;
    }
}
